package com.cszy.yydqbfq.adapter

import android.content.Context
import android.graphics.Color
import android.view.ViewGroup
import android.widget.ImageView
import com.bumptech.glide.Glide
import com.chad.library.adapter4.BaseQuickAdapter
import com.chad.library.adapter4.viewholder.QuickViewHolder
import com.hbcysd.qybfq.R
import com.hjq.shape.layout.ShapeConstraintLayout


import com.lzx.starrysky.SongInfo

class SongDeailPopAdapter : BaseQuickAdapter<SongInfo, QuickViewHolder>() {
    private var selectPosition: Int = -1;
    override fun onBindViewHolder(holder: QuickViewHolder, position: Int, item: SongInfo?) {
        holder.setText(R.id.tv_music_name, item?.songName)
        holder.setText(R.id.tv_music_author, item?.artist)
        Glide.with(context)
            .load(item?.songCover)
            .placeholder(R.mipmap.ic_default)
            .error(R.mipmap.ic_default)
            .into(holder.getView(R.id.iv_music_cover))
        val shapeConstraintLayout =
            holder.getView<ShapeConstraintLayout>(R.id.root_view)
        if (selectPosition == position) {
            shapeConstraintLayout.shapeDrawableBuilder.strokeColor = Color.parseColor("#82F7ED")
            holder.getView<ImageView>(R.id.iv_music_img).setImageResource(R.mipmap.ic_bofang_pause)
        } else {
            shapeConstraintLayout.shapeDrawableBuilder.strokeColor = Color.parseColor("#ffffff")
            holder.getView<ImageView>(R.id.iv_music_img).setImageResource(R.mipmap.ic_bofang_pop)
        }
        holder.setVisible(R.id.tv_music_state, selectPosition == position)
        shapeConstraintLayout.shapeDrawableBuilder.buildBackgroundDrawable()
        shapeConstraintLayout.invalidate()

    }

    override fun onCreateViewHolder(
        context: Context,
        parent: ViewGroup,
        viewType: Int
    ): QuickViewHolder {
        return QuickViewHolder(R.layout.item_pop_list, parent)
    }

    fun setPosition(position: Int) {
        this.selectPosition = position;
        notifyDataSetChanged()
    }
}